package ognl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import model.Cat;
import model.Dog;
import model.User;
import myaction.UserAction;

public class OgnlAction extends UserAction {

	private Cat myCat;
	private List<User> myUsers;
	private Set<Dog> myDogs;
	private Map<User, Dog> myOwnerships;

	public static String staticActionMethod() {
		return "this is a static method in the class ognlAction.";
	}

	public OgnlAction() {
		myUsers = new ArrayList<User>();
		myDogs = new HashSet<Dog>();
		myOwnerships = new HashMap<User, Dog>();
		initializeContainers();
	}

	private void initializeContainers() {
		for (int i = 0; i < 3; i++) {
			User user = new User(
					new String(new StringBuffer().append((char)('a' + i))), ""
							+ (char)('a' + i), i); // weird haha
			myUsers.add(user);
			Dog dog = new Dog("" + i);
			myDogs.add(dog);
			myOwnerships.put(user, dog);
		}
	}

	public Cat getCat() {
		return myCat;
	}

	public void setCat(Cat cat) {
		myCat = cat;
	}

	/**
	 * @return String or any object that has toString method
	 */
	public String actionMethod() {
		return "this is a method in the class OgnlAction.";
	}

	public List<User> getUsers() {
		return myUsers;
	}

	public void setUsers(List<User> users) {
		myUsers = users;
	}

	public Set<Dog> getDogs() {
		return myDogs;
	}

	public void setDogs(Set<Dog> dogs) {
		myDogs = dogs;
	}

	public Map<User, Dog> getOwnerships() {
		return myOwnerships;
	}

	public void setOwnerships(Map<User, Dog> ownerships) {
		myOwnerships = ownerships;
	}
}
